#include "boot_key.h"
#include <stdio.h>

QueueHandle_t bootkey_evt_queue = NULL;                 //定义队列句柄


static void BootKey_Isr_Handler(void *arg)
{
    uint32_t gpio_num = (uint32_t) arg;                         //获取入口参数
    xQueueSendFromISR(bootkey_evt_queue, &gpio_num, NULL);      //将入口参数即Pin号发送到队列
}

void Boot_Key_init(void)
{
    gpio_config_t BootKeyPin_conf = {
        .intr_type = GPIO_INTR_NEGEDGE,                 //下降沿中断
        .mode = GPIO_MODE_DEF_INPUT,                    //输入模式
        .pin_bit_mask = 1 << GPIO_NUM_0,                //选择GPIO0
        .pull_down_en = 0,                              //禁止内部下拉
        .pull_up_en = 1                                 //使能内部上拉
    };

    //根据上面的配置，设置GPIO0
    gpio_config(&BootKeyPin_conf);
    //创建一个队列处理bootkey事件
    bootkey_evt_queue = xQueueCreate(5, sizeof(uint32_t));
    //创建BootKey中断服务号
    gpio_install_isr_service(0);
    //给BootKey添加中段处理
    gpio_isr_handler_add(GPIO_NUM_0, BootKey_Isr_Handler, (void *)GPIO_NUM_0);

}